﻿using System;
using TechTalk.SpecFlow;
using UnityScenarios;
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using NUnit.Framework;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.PageObjects;
using System.Threading;

namespace UnityScenarios
{
    [Binding]
    public class ValidateLoginPageSteps
    {
        [Given]
        public void Given_the_Unity_URL_is_correct()
        {
            IWebDriver browser;
            ScenarioContext.Current.ContainsKey("browser");
            ScenarioContext.Current["browser"] = new FirefoxDriver();
            browser = ScenarioContext.Current["browser"] as FirefoxDriver;
            browser.Url = "http://dev.nexdox.com/Unity/session/new";
            browser.Manage().Window.Maximize();
            // ScenarioContext.Current.Pending();
        }

        [Given]
        public void Given_Username_input_field_is_present()
        {
            var ie = ScenarioContext.Current["browser"] as FirefoxDriver;
            Assert.IsTrue(ie.FindElement(By.Id("UserName")).Enabled); //This is to verify input field is present
        }

        [Given]
        public void Given_Password_input_field_is_present()
        {
            var ie = ScenarioContext.Current["browser"] as FirefoxDriver;
            Assert.IsTrue(ie.FindElement(By.Id("Password")).Enabled);
        }

        [Then]
        public void Then_the_Unity_logon_page_is_displayed()
        {
            var ie = ScenarioContext.Current["browser"] as FirefoxDriver;
            ie.PageSource.Contains("Logon");

            ie.Close();
            ie.Dispose();
        }
    }
}
